package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.service.IMyMoenyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 定义我的钱包
 */
@RestController
@RequestMapping("mymoneys")
public class MyMoneyController {
    @Autowired
    private IMyMoenyService myMoenyService;

    @GetMapping("{userId}")
    public Object selectByUserId(@PathVariable Long userId) {

        return myMoenyService.selectByUserId(userId);
    }

    /**
     * 提现
     * @param userId
     * @param rmb
     * @return
     */
    @PutMapping("{userId}")
    public Object updataByUserId(@PathVariable Long userId,  Integer rmb) {
        JSONResult result = new JSONResult();
        try {
            myMoenyService.updataByUserId(userId, rmb);
        } catch (Exception e) {
            result.mark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 充值
     * @param userId
     * @param rmb
     * @return
     */
    @PutMapping("/addmoneys/{userId}")
    public Object addmoneysUpdataByUserId(@PathVariable Long userId,  Integer rmb) {
        JSONResult result = new JSONResult();
        try {
            myMoenyService.addmoneysUpdataByUserId(userId, rmb);
        } catch (Exception e) {
            result.mark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

}
